﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Security;
using System.Xml;
using System.Reflection;

namespace Shopping.Common
{
    /// <summary>
    /// by 赵国伟；2009-10-15； 公共的静态方法；
    /// </summary>
    public class Utility
    {

        #region "获取Get参数中指定键的名称；"
        /// <summary>
        /// 获取Get参数中指定键的名称；
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <returns></returns>
        public static T G<T>(string key)
        {
            string v = HttpContext.Current.Request.QueryString[key] + "";
            T t = (T)InvokeUtiltyClass( "Cast2" + typeof(T).Name.ToLower(), new object[] { v });
            return t;
        }
        #endregion

        #region "获取Post参数中指定键的名称；"
        /// <summary>
        /// 获取Post参数中指定键的名称；
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <returns></returns>
        public static T P<T>(string key)
        {
            string v = HttpContext.Current.Request.Form[key] + "";
            T t = (T)InvokeUtiltyClass("Cast2" + typeof(T).Name.ToLower(), new object[] { v });
            return t;
        }
        #endregion

        #region "反射调用指定类的方法 by 赵国伟 2012-03-24"
        /// <summary>
        /// 反射调用指定类的方法；
        /// </summary>
        /// <param name="className"></param>
        /// <param name="method"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        private static object InvokeUtiltyClass(string method, object[] param)
        {
            Type objClass = typeof(Utility);
            return objClass.InvokeMember(method, BindingFlags.Default | BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Static, null, null, param);
        }
        #endregion

        #region "一组获取Get请求或者Post请求的指定键的值  by 赵国伟 2010-09-20"
        /// <summary>
        /// 获取Get请求中的指定参数；
        /// </summary>
        /// <param name="key">键名</param>
        /// <returns></returns>
        public static string G(string key)
        {
            string s = HttpContext.Current.Request.QueryString[key] + "";
            return s.Trim();
        }
        /// <summary>
        /// 获取Post请求中的指定参数；
        /// </summary>
        /// <param name="key">键名</param>
        /// <returns></returns>
        public static string P(string key)
        {
            string s = HttpContext.Current.Request.Form[key] + "";
            return s.Trim();
        }
        #endregion

        #region "强制将一个Object转换为string"
        /// <summary>
        /// 强制将一个Object转换为string,如果转换失败，返回""
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static string Cast2string(object value)
        {
            string s = "";
            try
            {
                s = Convert.ToString(value, System.Globalization.CultureInfo.CurrentCulture);
            }
            catch
            {

            }
            return s;
        }
        #endregion

        #region "强制将一个Object转换为int,如果转换失败，返回0 by 赵国伟"
        /// <summary>
        /// 强制将一个Object转换为int,如果转换失败，返回0
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static int Cast2int(object value)
        {
            int i = 0;
            try
            {
                i = Convert.ToInt32(value);
            }
            catch
            {

            }
            return i;
        }
        public static int Cast2int32(object value)
        {
            return Cast2int(value);
        }
        #endregion

        #region "强制将一个Object转换为decimal, by 赵国伟"
        /// <summary>
        /// 强制将一个Object转换为decimal,如果转换失败，返回""
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static decimal Cast2decimal(object value)
        {
            decimal s = 0.00M;
            try
            {
                s = Convert.ToDecimal(value); ;
            }
            catch
            {

            }
            return s;
        }
        #endregion

        #region "强制将一个Object转换为dateTime by 赵国伟
        /// <summary>
        /// 强制将一个Object转换为DateTime
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static DateTime Cast2datetime(object value)
        {
            DateTime s = new DateTime();
            try
            {
                s = Convert.ToDateTime(value); ;
            }
            catch
            {

            }
            return s;
        }
        #endregion

        #region "强制将一个Object转换为bool,by 赵国伟"
        /// <summary>
        /// 强制将一个Object转换为bool,
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static bool Cast2bool(object value)
        {
            bool s = false;
            try
            {
                s = Convert.ToBoolean(value);
            }
            catch
            {

            }
            return s;
        }
        #endregion

        #region "强制将字符串转换为Decimal  by 赵国伟"
        /// <summary>
        /// 强制将字符串转换为Decimal
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static Decimal String2Decimal(string value)
        {
            Decimal ret = 0;
            try
            {
                ret = Decimal.Parse(value, System.Globalization.CultureInfo.CurrentCulture);
            }
            catch
            {

            }
            return ret;
        }
        #endregion

        #region "将指定的url参数赋值到当前Url中，如果如果当前Url存在改参数，则替换值，否则添加该参数 by 赵国伟"

        public static string GetNewUrl(string paramName, string paramValue, bool isContainCurPage)
        {
            return GetNewUrl(paramName, paramValue, null, null, isContainCurPage);
        }

        /// <summary>
        /// 返回需要追加或者替换的url地址；(以当前Url为来源)
        /// </summary>
        /// <param name="linkKey"></param>
        /// <param name="linkValue"></param>
        /// <returns></returns>
        public static string GetNewUrl(string paramName, string paramValue, string paramName2, string paramValue2, bool isContainCurPage)
        {
            return GetNewUrl(paramName, paramValue, paramName2, paramValue2, null, null, null, null, null, null, isContainCurPage);
        }
        public static string GetNewUrl(string paramName, string paramValue, string paramName2, string paramValue2, string paramName3, string paramValue3, bool isContainCurPage)
        {
            return GetNewUrl(paramName, paramValue, paramName2, paramValue2, paramName3, paramValue3, null, null, null, null, isContainCurPage);
        }
        public static string GetNewUrl(string paramName, string paramValue, string paramName2, string paramValue2, string paramName3, string paramValue3, string paramName4, string paramValue4, bool isContainCurPage)
        {
            return GetNewUrl(paramName, paramValue, paramName2, paramValue2, paramName3, paramValue3, paramName4, paramValue4, null, null, isContainCurPage);
        }

        public static string GetNewUrl(string paramName, string paramValue, string paramName2, string paramValue2, string paramName3, string paramValue3, string paramName4, string paramValue4, string paramName5, string paramValue5, bool isContainCurPage)
        {

            string newUrl = ""; //新的Url地址；
            string currentLink = "";
            if (!isContainCurPage)
                currentLink = GetWebPageUrlNoCurPage();
            else
                currentLink = GetWebPageUrl();

            if (paramName2 == null) paramName2 = "";
            if (paramName3 == null) paramName3 = "";
            if (paramName4 == null) paramName4 = "";
            if (paramName5 == null) paramName5 = "";

            string[] tmpLink = currentLink.Split(new char[] { '?' });
            if (tmpLink.Length == 1)
            {
                newUrl = tmpLink[0] + "?&" + paramName + "=" + HttpUtility.HtmlEncode(paramValue);
                if (!string.IsNullOrEmpty(paramName2))
                    newUrl += "&" + paramName2 + "=" + HttpUtility.HtmlEncode(paramValue2);
                if (!string.IsNullOrEmpty(paramName3))
                    newUrl += "&" + paramName3 + "=" + HttpUtility.HtmlEncode(paramValue3);
                if (!string.IsNullOrEmpty(paramName4))
                    newUrl += "&" + paramName4 + "=" + HttpUtility.HtmlEncode(paramValue4);
                if (!string.IsNullOrEmpty(paramName5))
                    newUrl += "&" + paramName5 + "=" + HttpUtility.HtmlEncode(paramValue5);

            }
            else
            {
                //当前Url富含参数的情况；
                string[] tmpOldParam = tmpLink[1].Split(new char[] { '&' }); //取得当前Url中的各个参数；
                string newParam = ""; //存储新的当前参数； 

                for (int i = 0; i < tmpOldParam.Length; ++i)
                {
                    if (!string.IsNullOrEmpty(tmpOldParam[i]))
                    {
                        string[] tmpOldKey = tmpOldParam[i].Split(new char[] { '=' });

                        if (tmpOldKey[0].ToLower() != paramName.ToString().ToLower() && tmpOldKey[0].ToLower() != paramName2.ToString().ToLower() && tmpOldKey[0].ToLower() != paramName3.ToString().ToLower() && tmpOldKey[0].ToLower() != paramName4.ToString().ToLower() && tmpOldKey[0].ToLower() != paramName5.ToString().ToLower())
                        {
                            newParam += tmpOldParam[i] + "&";
                        }
                    }
                }

                //对旧的Url键值处理完毕，处理当前要追加或者替换的新url键
                if (newParam != "")
                {
                    newParam += paramName + "=" + HttpUtility.HtmlEncode(paramValue);

                }
                else
                {
                    newParam += "&" + paramName + "=" + HttpUtility.HtmlEncode(paramValue);
                }

                if (!string.IsNullOrEmpty(paramName2))
                    newParam += "&" + paramName2 + "=" + HttpUtility.HtmlEncode(paramValue2);
                if (!string.IsNullOrEmpty(paramName3))
                    newParam += "&" + paramName3 + "=" + HttpUtility.HtmlEncode(paramValue3);
                if (!string.IsNullOrEmpty(paramName4))
                    newParam += "&" + paramName4 + "=" + HttpUtility.HtmlEncode(paramValue4);
                if (!string.IsNullOrEmpty(paramName5))
                    newParam += "&" + paramName5 + "=" + HttpUtility.HtmlEncode(paramValue5);
                newUrl = tmpLink[0] + "?" + newParam;

            }
            newUrl = newUrl.Replace("?&", "?");
            return newUrl;
        }
        #endregion

        #region "获得当前网页的地址【不带分页参数】 如果地址中包含curpage键 将自动过滤， 默认curpage为分页键值 by 赵国伟"
        /// <summary>
        /// 获得当前网页的地址【不带分页参数】 如果地址中包含curpage键 将自动过滤， 默认curpage为分页键值
        /// </summary>
        /// <returns></returns>
        public static string GetWebPageUrl()
        {
            string backUrl = "";
            string url = HttpContext.Current.Request.Url.ToString();
            string[] tmpUrl = url.Split(new string[] { "&curpage=" }, StringSplitOptions.None);


            if (tmpUrl[0].IndexOf("?") >= 0)
            {
                //GET方式， 获取QUeryString集合
                //backUrl = tmpUrl[0];
                backUrl = HttpContext.Current.Request.CurrentExecutionFilePath + "?";
                int j = 0;
                for (int i = 0; i < HttpContext.Current.Request.QueryString.Count; ++i)
                {
                    if (HttpContext.Current.Request.QueryString.Keys[i] != null)
                    {
                        if (j == 0)
                            backUrl += HttpContext.Current.Request.QueryString.Keys[i] + "=" + HttpUtility.UrlEncode(HttpContext.Current.Request.QueryString[i]);
                        else
                            backUrl += "&" + HttpContext.Current.Request.QueryString.Keys[i] + "=" + HttpUtility.UrlEncode(HttpContext.Current.Request.QueryString[i]);

                    }
                    j++;
                }
            }
            else
            {
                backUrl = url;
            }

            return backUrl;
        }



        public static string GetWebPageUrlNoCurPage()
        {
            string backUrl = "";
            string url = HttpContext.Current.Request.Url.ToString();
            string[] tmpUrl = url.Split(new string[] { "&curpage=" }, StringSplitOptions.None);


            if (tmpUrl[0].IndexOf("?") >= 0)
            {
                //GET方式， 获取QUeryString集合
                //backUrl = tmpUrl[0];
                backUrl = HttpContext.Current.Request.CurrentExecutionFilePath + "?";
                int j = 0;
                for (int i = 0; i < HttpContext.Current.Request.QueryString.Count; ++i)
                {
                    if (HttpContext.Current.Request.QueryString.Keys[i] != null && HttpContext.Current.Request.QueryString.Keys[i].ToLower() != "curpage")
                    {
                        if (j == 0)
                        {
                            backUrl += HttpContext.Current.Request.QueryString.Keys[i] + "=" + HttpUtility.UrlEncode(HttpContext.Current.Request.QueryString[i]);
                        }
                        else
                        {
                            backUrl += "&" + HttpContext.Current.Request.QueryString.Keys[i] + "=" + HttpUtility.UrlEncode(HttpContext.Current.Request.QueryString[i]);
                        }
                        j++;
                    }
                }
            }
            else
            {
                backUrl = url;
            }

            return backUrl;
        }
        #endregion

        #region "替换制定Url地址中的键名称 by 赵国伟"
        /// <summary>
        /// 替换制定Url地址中的键名称 by 赵国伟
        /// </summary>
        /// <param name="url"></param>
        /// <param name="paraName"></param>
        /// <param name="newParaValue"></param>
        /// <returns></returns>
        public static string ReplaceUrlQuery(string url, string paraName, string newParaValue)
        {
            if (string.IsNullOrEmpty(url))
            {
                return paraName + "=" + newParaValue;
            }
            string authority = "";
            string oldQuery = "";
            //如果是形如a.aspx?a=1&b=2
            string[] qs1 = url.Split('?');
            if (qs1 != null)
            {
                authority = qs1[0] + "?";
                if (qs1.Length == 1)
                {
                    oldQuery = "";
                }
                else
                {
                    oldQuery = qs1[1];
                }
            }

            string[] ps = oldQuery.Split('&');
            StringBuilder newQuery = new StringBuilder();
            bool isParamIn = false;//该参数是否已经存在
            foreach (string p in ps)
            {
                string[] key = p.Split('=');
                string newKey = p;
                if (key != null)
                {
                    if (key[0] == paraName)
                    {
                        newKey = key[0] + "=" + HttpUtility.UrlEncode(newParaValue);
                        isParamIn = true;
                    }
                }
                newQuery.Append(newKey + "&");
            }
            if (!isParamIn)//如果参数不存在，返回
            {
                return authority + oldQuery + "&" + paraName + "=" + HttpUtility.UrlEncode(newParaValue);
            }
            newQuery.Length = newQuery.Length - 1;
            return authority + newQuery.ToString();
        }
        #endregion

        #region "通用的分页程序 by 赵国伟"
        /// <summary>
        /// 返回分页信息；
        /// </summary>
        /// <param name="curpage">当前页面</param>
        /// <param name="pageMaxRecord">每页最大记录数；</param>
        /// <param name="countPerPage"></param>
        /// <param name="totalcount">记录总数；</param>
        /// <returns></returns>
        public static string GetPageLine(string link, int curpage, int pageMaxRecord, int countPerPage, int totalCount)
        {
            if (pageMaxRecord <= 0) return "";
            int totalPage = totalCount % pageMaxRecord > 0 ? totalCount / pageMaxRecord + 1 : totalCount / pageMaxRecord;

            StringBuilder sb = new StringBuilder();
            //处理页标越界的情况；
            if (curpage <= 0)
                curpage = 1;

            if (curpage > totalPage)
                curpage = totalPage;

            int curLinkPage = (curpage - 1) / countPerPage;
            if (curpage == 1)
            {
                sb.Append("<span>首页</span><span>上一页</span>");
            }
            else
            {
                sb.Append("<a href=\"" + ReplaceUrlQuery(link, "curpage", "1") + "\">首页</a><a href=\"" + ReplaceUrlQuery(link, "curpage", (curpage - 1).ToString()) + "\">上一页</a>");
            }

            if ((curpage - 1) / countPerPage > 0)
            {
                sb.Append("<A href=" + ReplaceUrlQuery(link, "curpage", ((curLinkPage - 1) * countPerPage + countPerPage).ToString()) + ">上" + countPerPage.ToString() + "页</A>");
            }

            for (int i = curLinkPage * countPerPage; i < curLinkPage * countPerPage + countPerPage; ++i)
            {
                if (totalPage > i)
                {
                    if (i == (curpage - 1))
                    {
                        sb.Append("<a href=\"" + ReplaceUrlQuery(link, "curpage", (i + 1).ToString()) + "\" class=\"here\">" + (i + 1).ToString() + "</a>");
                    }
                    else
                    {
                        sb.Append("<a href=\"" + ReplaceUrlQuery(link, "curpage", (i + 1).ToString()) + "\" >" + (i + 1).ToString() + "</a>");
                    }
                }
            }
            //下X页的版面数量
            int indexCount = totalPage % countPerPage > 0 ? totalPage / countPerPage + 1 : totalPage / countPerPage;
            //最后一个版面的最小页数
            int minPage = countPerPage * (indexCount - 1) + 1;

            //if (curPageNo / maxLinkCount < TotalPage / maxLinkCount && maxLinkCount < TotalPage && (curPageNo + 1) < TotalPage)
            if ((curpage) < minPage)//如果当前页小于最后一个版面的页数，就显示下X页
            {
                sb.Append("<A   href=" + ReplaceUrlQuery(link, "curpage", ((curLinkPage + 1) * countPerPage + 1).ToString()) + ">下" + countPerPage + "页</A>");
            }


            if (curpage == totalPage)
            {
                sb.Append("<span>下一页</span><span>尾页</span>");
            }
            else
            {
                sb.Append("<a href=\"" + ReplaceUrlQuery(link, "curpage", (curpage + 1).ToString()) + "\">下一页</a><a href=\"" + ReplaceUrlQuery(link, "curpage", totalPage.ToString()) + "\">尾页</a>");
            }

            sb.Append("<span style=\"color:#000\">共" + totalCount + "条记录</span>");

            return sb.ToString();

        }


        public static string GetPageLineEx(string link, int curpage, int pageMaxRecord, int countPerPage, int totalCount)
        {
            if (pageMaxRecord <= 0) return "";
            int totalPage = totalCount % pageMaxRecord > 0 ? totalCount / pageMaxRecord + 1 : totalCount / pageMaxRecord;
            if (totalPage == 1)
                return "";
            StringBuilder sb = new StringBuilder();
            //处理页标越界的情况；
            if (curpage <= 0)
                curpage = 1;

            if (curpage > totalPage)
                curpage = totalPage;

            int curLinkPage = (curpage - 1) / countPerPage;
            if (curpage > 1)
            {
                sb.Append("<span class=\"w70\"><a href=\"" + ReplaceUrlQuery(link, "curpage", (curpage - 1).ToString()) + "\">上一页</a></span>");
            }
            for (int i = curLinkPage * countPerPage; i < curLinkPage * countPerPage + countPerPage; ++i)
            {
                if (totalPage > i)
                {
                    if (i == (curpage - 1))
                    {
                        sb.Append("<a href=\"" + ReplaceUrlQuery(link, "curpage", (i + 1).ToString()) + "\" class=\"on_page\">" + (i + 1).ToString() + "</a>");
                    }
                    else
                    {
                        sb.Append("<a href=\"" + ReplaceUrlQuery(link, "curpage", (i + 1).ToString()) + "\" >" + (i + 1).ToString() + "</a>");
                    }
                }
            }
            //下X页的版面数量
            int indexCount = totalPage % countPerPage > 0 ? totalPage / countPerPage + 1 : totalPage / countPerPage;
            //最后一个版面的最小页数
            int minPage = countPerPage * (indexCount - 1) + 1;

            if (curpage < totalPage)
            {
                sb.Append("<span class=\"w70\"><a href=\"" + ReplaceUrlQuery(link, "curpage", (curpage + 1).ToString()) + "\">下一页</a></span>");
            }
            return sb.ToString();
        }
        #endregion

        #region "通过比较获得指定默认值"
        /// <summary>
        /// 通过比较获得指定默认值
        /// </summary>
        /// <param name="defaultValue"></param>
        /// <param name="currentValue"></param>
        /// <returns></returns>
        public static string GetDefaultValue(string defaultValue, string currentValue)
        {
            if (string.IsNullOrEmpty(currentValue))
                return defaultValue;
            return currentValue;
        }
        #endregion

        #region "生成唯一的编号； by 赵国伟 2009-10-26 未经详细测试：慎用"
        /// <summary>
        ///生成唯一的编号；
        /// </summary>
        /// <returns></returns>
        public static string GenerateStringID()
        {
            byte[] buffer = Guid.NewGuid().ToByteArray();
            return BitConverter.ToInt32(buffer, 0).ToString().Replace("-", "0");
        }
        #endregion

        #region "计算两个日期相差的月份 by 赵国伟 2009-11-1； "
        /// <summary>
        /// 计算两个日期相差的月份；
        /// </summary>
        /// <param name="time1"></param>
        /// <param name="time2"></param>
        /// <returns></returns>
        public static int GetMonthNumBetweenTwoDateTime(DateTime startDate, DateTime endDate)
        {
            int i = (endDate.Year - startDate.Year) * 12;
            int j = endDate.Month - startDate.Month;
            return Math.Abs(i + j);
        }
        public static int GetMonthNumBetweenTwoDateTimeEx(DateTime startDate, DateTime endDate)
        {
            int i = (endDate.Year - startDate.Year) * 12;
            int j = endDate.Month - startDate.Month;
            return (i + j);
        }
        #endregion

        #region "计算两个日期相差的天数 by 赵国伟  2009-11-1"
        /// <summary>
        /// 计算两个日期相差的天数；
        /// </summary>
        /// <param name="time1"></param>
        /// <param name="time2"></param>
        /// <returns></returns>
        public static int GetDayNumBetweenTwoDateTime(DateTime startDate, DateTime endDate)
        {
            System.TimeSpan TS = new System.TimeSpan(endDate.Ticks - startDate.Ticks);
            return Utility.Cast2int(TS.TotalDays);
        }
        #endregion

        #region "返回对应的星期编号；  by 赵国伟 2009-11-1"
        /// <summary>
        /// 返回对应的星期编号；
        /// </summary>
        /// <param name="weekName"></param>
        /// <returns></returns>
        public static string GetWeekNum(string weekName)
        {
            int weekNum = -1;
            switch (weekName)
            {
                case "Monday":
                    weekNum = 0;
                    break;
                case "Tuesday":
                    weekNum = 1;
                    break;
                case "Wednesday":
                    weekNum = 2;
                    break;
                case "Thursday":
                    weekNum = 3;
                    break;
                case "Friday":
                    weekNum = 4;
                    break;
                case "Saturday":
                    weekNum = 5;
                    break;
                case "Sunday":
                    weekNum = 6;
                    break;
            }
            return weekNum.ToString();
        }



        /// <summary>
        /// 返回对应的星期编号；
        /// </summary>
        /// <param name="weekName"></param>
        /// <returns></returns>
        public static string GetWeekCnName(string weekName)
        {
            string cnName = "";
            switch (weekName)
            {
                case "Monday":
                    cnName = "一";
                    break;
                case "Tuesday":
                    cnName = "二";
                    break;
                case "Wednesday":
                    cnName = "三";
                    break;
                case "Thursday":
                    cnName = "四";
                    break;
                case "Friday":
                    cnName = "五";
                    break;
                case "Saturday":
                    cnName = "六";
                    break;
                case "Sunday":
                    cnName = "日";
                    break;
            }
            return cnName;
        }

        public static string GetWeekEnName(string weekCnName)
        {
            switch (weekCnName)
            {
                case "一":
                    return "M";
                case "二":
                    return "T";
                case "三":
                    return "W";
                case "四":
                    return "T";
                case "五":
                    return "F";
                case "六":
                    return "S";
                case "日":
                    return "S";
                default:
                    return "";

            }
        }

        public static string GetMonthEnName(string datestr)
        {
            if (string.IsNullOrEmpty(datestr))
                return "";
            return DateTime.Parse(datestr).ToString("MMMM", new System.Globalization.DateTimeFormatInfo());
        }

        #endregion

        #region 判断字符串是否是数字
        /// <summary>
        /// 判断字符串是否是数字
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static bool IsNumber(string obj)
        {
            if (string.IsNullOrEmpty(obj))
            {
                return false;
            }
            return Regex.IsMatch(obj, @"^\d+$");
        }

        #endregion

        #region "返回所需要的前几个字符，.[默认不加省略号  在调试的时候可以打开 可以看到字符充满时是否折行] by 赵国伟 2009-11-27"
        /// <summary>
        /// 返回所需要的前几个字符，并加上省略号...
        /// </summary>
        /// <param name="src"></param>
        /// <param name="max"></param>
        /// <returns></returns>
        public static string GetMaxString(string str, int length)
        {
            return GetMaxString(str, length, true);
        }
        public static string GetMaxString(string str, int length, bool isOutTip)
        {
            string strResult = string.Empty;
            if (str == null || str == "" || length == 0)
            {
                return strResult;
            }
            //字符串的字节长度
            int lengthByte = System.Text.Encoding.Default.GetBytes(str).Length;
            //如果指定的字节数小于等于字符串的字节数
            if (lengthByte > length)
            {
                for (int i = 1; i <= str.Length; i++)
                {
                    string temp = string.Empty;
                    //截取字符串
                    temp = str.Substring(0, i);
                    //字符串截取后的字节长度
                    int length2 = System.Text.Encoding.Default.GetBytes(temp).Length;
                    if (length2 > length)
                    {
                        strResult = str.Substring(0, i - 1);
                        break;
                    }
                    if (length2 == length)
                    {
                        strResult = temp;
                        break;
                    }
                }
                if (isOutTip)
                    strResult += "..";
            }
            else
            {
                //StringBuilder sb = new StringBuilder();
                //for (int j = 0; j < length - lengthByte; j++)
                //{
                // sb.Append("..");
                // }
                // strResult = str + sb.ToString();
                strResult = str;
            }

            //返回结果
            return strResult;
        }
        #endregion

        #region "将金额转换为人民币大写  by 赵国伟 2009-11-27"
        /// <summary> 
        /// 将金额转换为人民币大写 
        /// </summary> 
        /// <param name="num">金额</param> 
        /// <returns>返回大写形式</returns> 
        public static string CmycurD(decimal num)
        {
            string str1 = "零壹贰叁肆伍陆柒捌玖";            //0-9所对应的汉字 
            string str2 = "万仟佰拾亿仟佰拾万仟佰拾元角分"; //数字位所对应的汉字 
            string str3 = "";    //从原num值中取出的值 
            string str4 = "";    //数字的字符串形式 
            string str5 = "";  //人民币大写金额形式 
            int i;    //循环变量 
            int j;    //num的值乘以100的字符串长度 
            string ch1 = "";    //数字的汉语读法 
            string ch2 = "";    //数字位的汉字读法 
            int nzero = 0;		//用来计算连续的零值是几个 
            int temp;            //从原num值中取出的值 

            num = Math.Round(Math.Abs(num), 2);    //将num取绝对值并四舍五入取2位小数 
            str4 = ((long)(num * 100)).ToString();        //将num乘100并转换成字符串形式 
            j = str4.Length;      //找出最高位 
            if (j > 15) { return "溢出"; }
            str2 = str2.Substring(15 - j);   //取出对应位数的str2的值。如：200.55,j为5所以str2=佰拾元角分 

            //循环取出每一位需要转换的值 
            for (i = 0; i < j; i++)
            {
                str3 = str4.Substring(i, 1);          //取出需转换的某一位的值 
                temp = Convert.ToInt32(str3);      //转换为数字 
                if (i != (j - 3) && i != (j - 7) && i != (j - 11) && i != (j - 15))
                {
                    //当所取位数不为元、万、亿、万亿上的数字时 
                    if (str3 == "0")
                    {
                        ch1 = "";
                        ch2 = "";
                        nzero = nzero + 1;
                    }
                    else
                    {
                        if (str3 != "0" && nzero != 0)
                        {
                            ch1 = "零" + str1.Substring(temp * 1, 1);
                            ch2 = str2.Substring(i, 1);
                            nzero = 0;
                        }
                        else
                        {
                            ch1 = str1.Substring(temp * 1, 1);
                            ch2 = str2.Substring(i, 1);
                            nzero = 0;
                        }
                    }
                }
                else
                {
                    //该位是万亿，亿，万，元位等关键位 
                    if (str3 != "0" && nzero != 0)
                    {
                        ch1 = "零" + str1.Substring(temp * 1, 1);
                        ch2 = str2.Substring(i, 1);
                        nzero = 0;
                    }
                    else
                    {
                        if (str3 != "0" && nzero == 0)
                        {
                            ch1 = str1.Substring(temp * 1, 1);
                            ch2 = str2.Substring(i, 1);
                            nzero = 0;
                        }
                        else
                        {
                            if (str3 == "0" && nzero >= 3)
                            {
                                ch1 = "";
                                ch2 = "";
                                nzero = nzero + 1;
                            }
                            else
                            {
                                if (j >= 11)
                                {
                                    ch1 = "";
                                    nzero = nzero + 1;
                                }
                                else
                                {
                                    ch1 = "";
                                    ch2 = str2.Substring(i, 1);
                                    nzero = nzero + 1;
                                }
                            }
                        }
                    }
                }
                if (i == (j - 11) || i == (j - 3))
                {
                    //如果该位是亿位或元位，则必须写上 
                    ch2 = str2.Substring(i, 1);
                }
                str5 = str5 + ch1 + ch2;

                if (i == j - 1 && str3 == "0")
                {
                    //最后一位（分）为0时，加上“整” 
                    str5 = str5 + '整';
                }
            }
            if (num == 0)
            {
                str5 = "零元整";
            }
            return str5;
        }
        #endregion

        #region "将一组单个的日期集合中的连续日期转化为 时间区间 by 赵国伟 2009-12-01"
        /// <summary>
        /// 将一组单个的日期集合中的连续日期转化为 时间区间；
        /// </summary>
        /// <param name="days"></param>
        /// <returns></returns>
        public static Dictionary<string, string> ConvertDaysToPeriod(string[] days)
        {
            Dictionary<string, string> sd = null;
            if (days == null)
                return sd;
            DateTime dt;
            string startDate = "";
            sd = new Dictionary<string, string>();

            for (int i = 0; i < days.Length; ++i)
            {
                days[i] = DateTime.Parse(days[i]).ToString("yyyy-MM-dd");  //by 赵国伟 2011-03-31 批量整段排期传递过来的日期串 不是标准的yyyy-MM-dd格式，导致不能够合并日期；这里将传递过来的字符串强制格式化为yyyy-MM-dd格式
            }


            if (days.Length == 1)
            {

                sd.Add(days[0], days[0]);
            }
            else
            {
                int i = 0;
                while (i < days.Length - 1)
                {
                    dt = DateTime.Parse(days[i]);
                    startDate = days[i];
                    for (int j = i + 1; j < days.Length; ++j)
                    {
                        dt = dt.AddDays(1);
                        if (dt.ToString("yyyy-MM-dd") != days[j])
                        {
                            sd.Add(startDate, dt.AddDays(-1).ToString("yyyy-MM-dd"));
                            i = j;
                            break;
                        }
                        else
                        {
                            i++;
                            if (i == (days.Length - 1))
                            {
                                sd.Add(startDate, dt.ToString("yyyy-MM-dd"));

                            }

                        }

                    }
                    if (i == (days.Length - 1) && dt.ToString("yyyy-MM-dd") != days[i])
                        sd.Add(days[i], days[i]);

                }
            }

            return sd;
        }
        #endregion

        #region "根据路径读取文件内容  by 赵国伟 2009-01-11"
        /// 根据路径读取文件内容
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static string ReadFile(string path)
        {
            string str = "";

            try
            {
                StreamReader sr = new StreamReader(path, Encoding.GetEncoding("gb2312"));
                str = sr.ReadToEnd();
                sr.Close();

                return str;
            }
            catch
            {
                return str;
            }


        }
        #endregion

        #region "执行正则表达式来提取值 by zhaoguowei 2008-7-2"
        /// <summary>
        /// 执行正则提取出值
        /// </summary>
        /// <param name="RegexString">正则表达式</param>
        /// <param name="RemoteStr">HtmlCode源代码</param>
        /// <returns></returns>
        public static string GetRegValue(string RegexString, string RemoteStr)
        {
            string MatchVale = "";
            Regex r = new Regex(RegexString);
            Match m = r.Match(RemoteStr);
            if (m.Success)
            {
                MatchVale = m.Value;
            }
            else
            {
                MatchVale = RemoteStr;
            }
            return MatchVale;
        }

        #endregion

        #region "执行正则表达式来提取值 by zhaoguowei 2010-01-18"
        /// <summary>
        /// 执行正则表达式来提取值 by zhaoguowei 2010-01-18
        /// </summary>
        /// <param name="regexStr">正则表达式</param>
        /// <param name="sourceStr">原字符串</param>
        /// <param name="remoteStr">替换的字符串</param>
        /// <returns></returns>
        public static string GetRegValue(string regexStr, string sourceStr, string remoteStr)
        {
            Regex r = new Regex(regexStr);
            bool issuc = r.IsMatch(sourceStr);
            if (issuc)
            {
                return r.Replace(sourceStr, remoteStr);
            }
            return sourceStr;
        }
        #endregion

        #region "获取客户端的IP地址；  by 赵国伟 2010-01-14"
        /// <summary>
        /// 获取客户端的IP地址；
        /// </summary>
        /// <returns></returns>
        public static string GetClientIPAddress()
        {
            string Ip = string.Empty;
            if (HttpContext.Current != null)
            {
                // 穿过代理服务器取远程用户真实IP地址
                if (HttpContext.Current.Request.ServerVariables["HTTP_VIA"] != null)
                {
                    if (HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] == null)
                    {
                        if (HttpContext.Current.Request.ServerVariables["HTTP_CLIENT_IP"] != null)
                            Ip = HttpContext.Current.Request.ServerVariables["HTTP_CLIENT_IP"].ToString();
                        else
                            if (HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"] != null)
                                Ip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString();
                            else
                                Ip = "";
                    }
                    else
                        Ip = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
                }
                else if (HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"] != null)
                {
                    Ip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString();
                }
                else
                {
                    Ip = "";
                }
            }

            return Ip;

        }
        #endregion

        #region "向指定的泛型数组列表中 添加新项；添加新项之前；先判断是否存在；如果存在则不添加； by 赵国伟； 2010-01-20"
        /// <summary>
        /// 向指定的泛型数组列表中 添加新项；添加新项之前；先判断是否存在；如果存在则不添加；
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="obj"></param>
        /// <param name="item"></param>
        public static List<T> AddListArrayNewItem<T>(List<T> obj, T item)
        {
            if (obj.IndexOf(item) < 0)
            {
                obj.Add(item);
            }
            return obj;
        }
        #endregion

        #region "获取指定Cookies的值；by 赵国伟； 2010-01-20"
        /// <summary>
        /// 获取指定Cookies的值；
        /// </summary>
        /// <param name="cookieName"></param>
        /// <returns></returns>
        public static string GetCookies(string cookieName)
        {
            if (System.Web.HttpContext.Current.Request.Cookies[cookieName] != null)
                return System.Web.HttpContext.Current.Request.Cookies[cookieName].Value;
            else
                return "";

        }
        #endregion

        #region "设置Cookies；  by 赵国伟； 2010-01-20"
        /// <summary>
        /// 设置Cookies；  
        /// </summary>
        /// <param name="cookieName"></param>
        /// <param name="cookieValue"></param>
        /// <param name="cookieDomain"></param>
        /// <param name="expiresHours"></param>
        public static void SetCookies(string cookieName, string cookieValue, string cookieDomain, int expiresHours)
        {
            HttpCookie cookie = new HttpCookie(cookieName, cookieValue);
            cookie.Domain = cookieDomain;
            cookie.Path = "/";
            if (expiresHours > 0)
                cookie.Expires = DateTime.Now.AddHours(expiresHours);
            System.Web.HttpContext.Current.Response.AppendCookie(cookie);
        }
        #endregion

        #region "获取指定网页地址的全部内容 可指定编码类型； by 赵国伟 2010-02-02"
        /// <summary>
        /// 获取指定网页地址的全部内容
        /// </summary>
        /// <param name="url">目标网站地址</param>
        /// <param name="encodeType">编码类型</param>
        /// <returns></returns>
        public static string GetUrl(string url, string encodeType)
        {
            string result = "";
            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                System.Text.Encoding encoding = System.Text.Encoding.GetEncoding(encodeType);
                System.IO.StreamReader reader = new System.IO.StreamReader(response.GetResponseStream(), encoding);
                result = reader.ReadToEnd();
                reader.Close();
                response.Close();
                return result;
            }
            catch (WebException e)
            {
                result = e.Message;
                return result;
            }
        }
        #endregion

        #region "获取指定网页地址的全部内容   by 赵国伟 2010-02-02"
        /// <summary>
        /// 获取指定网页地址的全部内容
        /// </summary>
        /// <param name="url">目标网站地址</param>
        /// <returns></returns>
        public static string GetUrl(string url)
        {
            string result = "";
            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                System.Text.Encoding encoding = System.Text.Encoding.GetEncoding("gb2312");
                System.IO.StreamReader reader = new System.IO.StreamReader(response.GetResponseStream(), encoding);
                result = reader.ReadToEnd();
                reader.Close();
                response.Close();
                return result;

            }
            catch (WebException e)
            {
                result = e.Message;
                return result;
            }
        }
        #endregion

        #region "向指定的文件写入指定的内容；"
        /// <summary>
        /// 向指定的文件写入指定的内容；
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="fileContent"></param>
        public static void WriteToFile(string path, string fileName, string fileContent)
        {
            Directory.CreateDirectory(path);
            using (StreamWriter sw = new StreamWriter(path + fileName, true, Encoding.GetEncoding("gb2312")))
            {
                sw.Write(fileContent);
            }
        }



        public static void WriteToFile(string fileName, string fileContent)
        {

            using (StreamWriter sw = new StreamWriter(fileName, false, Encoding.GetEncoding("gb2312")))
            {
                sw.Write(fileContent);
            }
        }
        public static void WriteToFileEx(string fileName, string fileContent,string encode)
        {

            using (StreamWriter sw = new StreamWriter(fileName, false, Encoding.GetEncoding(encode)))
            {
                sw.Write(fileContent);
            }
        }
        #endregion

        #region "判断当前的下拉框选项的值 是否等于默认值 如果相等 返回选中的HTML标记；否则返回空；  by 赵国伟 2010-03-29"
        /// <summary>
        /// 判断当前的下拉框选项的值 是否等于默认值 如果相等 返回选中的HTML标记；否则返回空；
        /// </summary>
        /// <param name="curItemValue"></param>
        /// <param name="defaultValue"></param>
        /// <returns></returns>
        public static string GetddlObjectSelected(string curItemValue, string defaultValue)
        {
            if (defaultValue == curItemValue)
                return "Selected";
            return "";
        }
        #endregion

        #region "判断当前的复选框选项的值 是否等于默认值 如果相等 返回选中的HTML标记；否则返回空；  by 赵国伟 2010-03-29"
        /// <summary>
        /// 判断当前的下拉框选项的值 是否等于默认值 如果相等 返回选中的HTML标记；否则返回空；
        /// </summary>
        /// <param name="curItemValue"></param>
        /// <param name="defaultValue"></param>
        /// <returns></returns>
        public static string GetCheckObjectChecked(string curItemValue, string defaultValue)
        {
            if (defaultValue == curItemValue)
                return "Checked";
            return "";
        }
        #endregion

        #region "删除指定目录下 非当日创建的文件"
        /// <summary>
        /// 删除指定目录下 非当日创建的文件
        /// </summary>
        /// <param name="filePath"></param>
        public static void DeleteInvalidFile(string filePath)
        {
            if (!Directory.Exists(filePath))
                return;

            string[] files = Directory.GetFiles(filePath);
            if (files != null)
            {
                for (int i = 0; i < files.Length; ++i)
                {
                    FileInfo fileinfo = new FileInfo(files[i]);
                    if (fileinfo.CreationTime.ToShortDateString() != DateTime.Now.ToShortDateString())
                    {
                        File.Delete(files[i]);
                    }
                }
            }


        }
        #endregion

       

        #region 格式化金额格式  by 赵国伟 2010-07-27 
        /// <summary>
        /// 格式化为标准的金额显示；
        /// </summary>
        /// <param name="money"></param>
        /// <returns></returns>
        public static string FormatMoneyStr(decimal money)
        {
            string result = "";
            try
            {
                double d = Convert.ToDouble(money);
                result = d.ToString("#,##0.00");
            }
            catch (Exception es)
            {
                result = "0.00";
            }
            return result;
        }
        #endregion

        #region "输出错误提示  by 赵国伟 2010-07-28"
        /// <summary>
        /// 输出错误提示
        /// </summary>
        /// <param name="tips"></param>
        public static void ShowErrorTips(string tips)
        {
            System.Web.HttpContext.Current.Response.Write("<script Language=\"javascript\">alert('" + tips + "');history.back();</script>");
            System.Web.HttpContext.Current.Response.End();
        }
        public static void ShowErrorTips(string tips,string backUrl)
        {
            System.Web.HttpContext.Current.Response.Write("<script Language=\"javascript\">alert('" + tips + "');location.href='" + backUrl + "';</script>");
            System.Web.HttpContext.Current.Response.End();
        }
        #endregion

        #region MD5加密
        /// <summary>
        /// 加密
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        public static string MD5(string text)
        {
            return FormsAuthentication.HashPasswordForStoringInConfigFile(text, "MD5");
        }
        #endregion

        #region "获得指定XML格式文档的指定节的值 by 赵国伟 2010-11-08"
        /// <summary>
        /// 获得指定XML格式文档的指定节的值
        /// </summary>
        /// <param name="xmlDoc"></param>
        /// <param name="nodeName"></param>
        /// <returns></returns>
        public static string GetSingleXmlNodeValue(string xmlDoc, string nodeName)
        {
            string nodeValue = "";
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(xmlDoc);
            XmlNodeList nodeList = doc.SelectNodes("//" + nodeName);
            if (nodeList != null)
            {
                nodeValue = nodeList[0].InnerText;
            }
            return nodeValue;
        }
        #endregion

        #region "移动指定地址的文件到指定的文件夹下； by 赵国伟 2011-01-23"
        /// <summary>
        /// 移动指定地址的文件到指定的文件夹下；
        /// </summary>
        /// <param name="sourceUrl">目标文件URL</param>
        /// <param name="newPath">新路径</param>
        /// <returns></returns>
        public static ReturnValue MoveFileByUrl(string sourceUrl, string newPath)
        {
            ReturnValue ret = new ReturnValue(ResultType.Fail);
            try
            {
                string oldPath = HttpContext.Current.Server.MapPath(sourceUrl);
                string newfileName = "";
                if (newPath.EndsWith("\\"))
                {
                    newfileName = newPath + Path.GetFileName(oldPath);
                }
                else
                {
                    newfileName = newPath + "\\" + Path.GetFileName(oldPath);
                }
                if (!Directory.Exists(newPath))
                    Directory.CreateDirectory(newPath);
                 File.Copy(oldPath, newfileName, true);
                // File.Move(oldPath, newfileName);
                ret.Result = ResultType.Success;
                ret.Message = "文件移动成功";
            }
            catch (Exception e)
            {
                ret.Message = e.Message;
            }
            return ret;
        }
        #endregion

        #region "输出禁止页面缓存的代码 by 赵国伟 2010-11-17"
        /// <summary>
        /// 输出禁止页面缓存的代码
        /// </summary>
        public static void ResponseNoCache()
        {
            //禁止页面缓存；
            HttpContext.Current.Response.Buffer = true;
            HttpContext.Current.Response.ExpiresAbsolute = DateTime.Now.AddDays(-1);
            HttpContext.Current.Response.Cache.SetExpires(DateTime.Now.AddDays(-1));
            HttpContext.Current.Response.CacheControl = "no-cache";
            HttpContext.Current.Response.Expires = 0;
            HttpContext.Current.Response.Cache.SetNoStore();
        }
        #endregion

        #region "将decimal数值转化为货币格式 并去除货币标识 by 赵国伟 2011-04-12"
        /// <summary>
        /// 将decimal数值转化为货币格式 并去除货币标识
        /// </summary>
        /// <param name="num"></param>
        /// <returns></returns>
        public static string ConvertDecimalToMoney(decimal num)
        {
            return num.ToString("C").Replace("￥", "");
        }
        #endregion

        #region "冒泡排序  by 赵国伟 2011-05-22"
        /// <summary>
        /// 冒泡排序
        /// </summary>
        /// <param name="listOfSource"></param>
        public static void BobbleSort(List<int> listOfSource)
        {
            for (int i = 0; i < listOfSource.Count - 1; ++i)
            {
                for (int j = i + 1; j < listOfSource.Count; ++j)
                {
                    if (listOfSource[i] > listOfSource[j])
                    {
                        int tmp = listOfSource[j];
                        listOfSource[j] = listOfSource[i];
                        listOfSource[i] = tmp;
                    }
                }
            }
        }
        #endregion

        #region "获取指定对象的属性名称，并保存为Hash结构；GetAllPropertyName<T>() by 赵国伟 2011-06-29 "
        /// <summary>
        /// 获取指定对象的属性名称，并保存为Hash结构；
        /// </summary>
        /// <returns></returns>
        public static HashSet<string> GetAllPropertyName<T>()
        {
            HashSet<string> hash = new HashSet<string>();
            Type t = typeof(T);
            foreach (System.Reflection.PropertyInfo data in t.GetProperties())
            {
                hash.Add(data.Name);
            }
            return hash;
        }
        #endregion

        #region "将指定的枚举类型输出为下拉框选项； by 赵国伟 2012-04-05"
        /// <summary>
        /// 将指定的枚举类型输出为下拉框选项；
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="defaultValue"></param>
        /// <returns></returns>
        public static string GetEnumToSelectOption<T>(string defaultValue)
            where T : struct
        {
            StringBuilder sb = new StringBuilder();
            foreach (T c in Enum.GetValues(typeof(T)))
            {
                sb.Append("<option value=\"");
                sb.Append(c.ToString());
                sb.Append("\" ");
                if (defaultValue == c.ToString())
                    sb.Append(" Selected ");
                sb.Append(">");
                sb.Append(c.ToString());
                sb.Append("</option>");
            }
            return sb.ToString();
        }
        #endregion

        #region "获取年份选择的下拉选项； by 赵国伟 2011-09-10"
        /// <summary>
        /// 获取年份选择的下拉选项；
        /// </summary>
        /// <param name="defaultValue"></param>
        /// <returns></returns>
        public static string GetYearsToSelectOptions(string defaultValue)
        {
            StringBuilder sbOptions = new StringBuilder();
            for (int i = 1; i >= -10; --i)
            {
                DateTime dt = DateTime.Now.AddYears(i);
                sbOptions.Append(string.Format("<option value=\"{0}\"  {1} />{2}</option>", dt.ToString("yyyy"), dt.ToString("yyyy") == defaultValue ? "Selected" : "", dt.ToString("yyyy年")));
            }

            return sbOptions.ToString();
        }
        #endregion

        #region "整形集合转为字符串集合； by 赵国伟 2012-04-22"
        /// <summary>
        /// 整形集合转为字符串集合；
        /// </summary>
        /// <param name="listOfInt"></param>
        /// <returns></returns>
        public static List<string> IntArrayToStringArray(List<int> listOfInt)
        {
            if (listOfInt == null) return null;

            List<string> listOfStr = new List<string>();
            foreach (int i in listOfInt)
                listOfStr.Add(i.ToString());
            return listOfStr;
        }
        #endregion

        #region "将Hash集合转化为列表集合； by 赵国伟 2012-05-06"
        /// <summary>
        /// 将Hash集合转化为列表集合；
        /// </summary>
        /// <typeparam name="T1"></typeparam>
        /// <typeparam name="T2"></typeparam>
        /// <param name="dict"></param>
        /// <returns></returns>
        public static List<T2> HashToList<T1,T2>(Dictionary<T1,T2> dict)
        {
            if (dict == null || dict.Count == 0)
                return null;
            List<T2> list = new List<T2>();
            foreach (KeyValuePair<T1, T2> k in dict)
                list.Add(k.Value);
            return list;
        }
        #endregion




    }
}
